@extends('backstage.layout.master')
@section('title', '推广列表')
@section('content')
    <style>
        .state li {
            list-style: none;
            float: left;
            padding: 0 20px;
            text-align: center;
            height: 40px;
            line-height: 40px;
        }

        .state ul {
            margin: 0;
        }

        .state a {
            font-size: 12px;
        }
        .che a {
            font-weight: bold;
            color: #7c7c7c;
        }
    </style>
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="backstage/home">主页</a>
            </li>

            <li class="active">
                <a href="/backstage/promo">推广</a>
            </li>
            <li>
                推广列表
            </li>
        </ul><!-- .breadcrumb -->

        <div class="nav-search" id="nav-search">
        </div><!-- #nav-search -->
    </div>

    <div class="page-content">
        <div class="page-header">
            <h1>
                推广
                <small>
                    <i class="icon-double-angle-right"></i>
                    推广列表
                </small>
                <span class="pull-right">
                    <button class="btn btn-primary" onclick="javascript:window.location.href='{{asset('')}}backstage/promo/add-promo';">添加推广</button>
                </span>
            </h1>
        </div>
        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="alert alert-info">
                    <i class="icon-hand-right"></i>
                    <!-- 信息-->
                </div>
                <div class="table-responsive">
                    <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th >编号</th>
                            <th >推广编号</th>
                            <th >推广名称</th>
                            <th>推广简介</th>
                            <th>更新时间</th>
                            <th width="150px">操作区</th>
                        </tr>
                        </thead>

                        <tbody>
                        @foreach ($promos as $promo)
                        <tr class="" data-tr-id="{{isset($promo->id)?$promo->id:''}}">
                            <td>
                                {{isset($promo->id)?$promo->id:''}}
                            </td>
                            <td>
                                {{isset($promo->promo_id)?$promo->promo_id:''}}
                            </td>
                            <td>
                                {{isset($promo->promo_name)?$promo->promo_name:''}}
                            </td>
                            <td>
                                {{isset($promo->description)?str_limit($promo->description, $limit = 60, $end = '...'):''}}
                            </td>
                            <td>
                                {{isset($promo->updated_at)?date('Y-m-d H:i:s',$promo->updated_at):''}}
                            </td>
                            <td class="center" style="padding-top: 15px">
                                <button onclick="deletePromo({{isset($promo->id)?$promo->id:0}})" class="btn btn-xs btn-info" data-rel="tooltip" title="删除">
                                    <i class="icon-trash bigger-120"></i>
                                </button>
                                <button onclick="javascript:window.location.href='{{asset('')}}backstage/promo/promo-res?id={{isset($promo->promo_id)?$promo->promo_id:''}}';" class="btn btn-xs btn-info" data-rel="tooltip" title="推广绑定">
                                    <i class="icon-zoom-in bigger-120"></i>
                                </button>
                            </td>
                        </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
                <div class="row">
                    <div class="col-sm-6">
                        <div class="dataTables_info" id="sample-table-2_info"></div>
                    </div>
                    <div class="col-sm-6">
                        <div class="dataTables_paginate paging_bootstrap">
                            <?php echo $promos->render(); ?>
                        </div>
                    </div>
                </div>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
    <script type="text/javascript">
        function deletePromo(id) {
            if(id==0){
                return false;
            }
            swal({
                title: "确定删除？",
                text: "",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                closeOnConfirm: true,
                closeOnCancel: true
            },function (){
                $.ajax({
                    type: "post",
                    url: "/backstage/promo/del-promo",
                    data:{"id":id},
                    dataType: 'json',
                    success: function(res){
                        if(res.state==1){
                            swal({
                                title:'删除成功！',
                                text: "",
                                type: "success",
                                timer:2000
                            });
                            $('[data-tr-id='+id+']').remove();
                        }else{
                            swal({
                                title: res.message,
                                text: "",
                                type: "error",
                                timer:3000
                            });
                        }
                    },
                    error:function(){
                        swal({
                            title: "系统繁忙！",
                            text: "",
                            type: "error",
                            timer:2000
                        });
                    }
                });//ajax
            });
        }
    </script>
@stop